home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / os-probes / 50mounted-tests
Text File  |  2009-09-14  |  2KB  |  75 lines

  1. #!/bin/sh
  2. # Sub-tests that require a mounted partition.
  3. set -e
  4. partition=$1
  5.  
  6. . /usr/share/os-prober/common.sh
  7.  
  8. tmpmnt=/var/lib/os-prober/mount
  9. if [ ! -d $tmpmnt ]; then
  10.     mkdir $tmpmnt
  11. fi
  12.  
  13. types="$(fs_type "$partition")" || types=NOT-DETECTED
  14. if [ "$types" = NOT-DETECTED ]; then
  15.     debug "$1 type not recognised; skipping"
  16.     exit 0
  17. elif [ "$types" = swap ]; then
  18.     debug "$1 is a swap partition; skipping"
  19.     exit 0
  20. elif [ "$types" = crypto_LUKS ]; then
  21.     debug "$1 is a LUKS partition; skipping"
  22.     exit 0
  23. elif [ "$types" = ntfs ]; then
  24.     if type ntfs-3g >/dev/null 2>&1; then
  25.         types='ntfs-3g ntfs'
  26.     fi
  27. elif [ -z "$types" ]; then
  28.     if type cryptsetup >/dev/null 2>&1 && \
  29.        cryptsetup luksDump "$partition" >/dev/null 2>&1; then
  30.         debug "$1 is a LUKS partition; skipping"
  31.         exit 0
  32.     fi
  33.     for type in $(grep -v nodev /proc/filesystems); do
  34.         # hfsplus filesystems are mountable as hfs. Try hfs last so
  35.         # that we can tell the difference.
  36.         if [ "$type" = hfs ]; then
  37.             delaytypes="${delaytypes:+$delaytypes }$type"
  38.         elif [ "$type" = fuseblk ]; then
  39.             if type ntfs-3g >/dev/null 2>&1; then
  40.                 types="${types:+$types }ntfs-3g"
  41.             fi
  42.         else
  43.             types="${types:+$types }$type"
  44.         fi
  45.     done
  46. fi
  47.  
  48. for type in $types $delaytypes; do
  49.     if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
  50.         debug "mounted as $type filesystem"
  51.         for test in /usr/lib/os-probes/mounted/*; do
  52.             debug "running subtest $test"
  53.             if [ -f $test ] && [ -x $test ]; then
  54.                 if $test "$partition" "$tmpmnt" "$type"; then
  55.                     debug "os found by subtest $test"
  56.                     if ! umount $tmpmnt; then
  57.                         warn "failed to umount $tmpmnt"
  58.                     fi
  59.                     rmdir $tmpmnt || true
  60.                     exit 0
  61.                 fi
  62.             fi
  63.         done
  64.         if ! umount $tmpmnt; then
  65.             warn "failed to umount $tmpmnt"
  66.         fi
  67.         break
  68.     fi
  69. done
  70.  
  71. rmdir $tmpmnt || true
  72.  
  73. # No tests found anything.
  74. exit 1
  75.